package com.tuanzhang.mall.seller.domain.valueobj;

import cn.hutool.core.util.StrUtil;
import com.tuanzhang.mall.seller.infrastructure.repository.SellerRepository;
import com.tuanzhang.mall.seller.interfaces.facade.QixinBusinessResultInfo;
import com.tuanzhang.mall.seller.types.exception.ApiException;
import lombok.Getter;
import lombok.ToString;

/**
 * 类功能描述
 *
 * @author wangyl
 * @date 2025/6/16
 */

@Getter
@ToString
public class CompanyInfo {

    private String address;


    private String name;

    private String companyLicenseId;

    private String companyLicenseUrl;

    /**
     * 营业执照ocr状态
     */
    private Integer companyLicenseUrlOcrStatus;

    private CompanyInfo(String address, String name, String companyLicenseId, String companyLicenseUrl) {
        this.address = address;
        this.name = name;
        this.companyLicenseId = companyLicenseId;
        this.companyLicenseUrl = companyLicenseUrl;
    }


    public static CompanyInfo create(String address, String name, String companyLicenseId, String companyLicenseUrl) {
        return new CompanyInfo(address, name, companyLicenseId, companyLicenseUrl);
    }

    public void checkCompanyLicenseId(QixinBusinessResultInfo qixinBusinessFace) {
        if (StrUtil.equals(qixinBusinessFace.getName(), this.name)) {
            this.companyLicenseUrlOcrStatus = 1;
        }else {
            this.companyLicenseUrlOcrStatus = 0;
        }
    }

    //聚合根的核心职责是‌维护自身边界内的业务规则与一致性‌（如状态校验、内部实体关系），而唯一性校验（如营业执照ID是否重复）属于‌跨聚合的全局规则‌，应由领域服务或应用层协调处理，并且带来了并发和事务的隐患
  /*  public void checkCompanyInfoRepeat(SellerRepository repo) {
        if (repo.existsByNameAndLicenseId(this.name, this.companyLicenseId)) {
            throw new ApiException("公司名称或统一社会信用代码重复，请检查后重新提交");
        }
    }*/
}
